<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/19
 * Time: 18:33
 */

namespace App\Http\Controllers\Admin;


use App\Http\Logics\Admin\PartnerLogic;
use App\Http\Traits\PartnerTrait;
use App\Http\Controllers\BaseController;
class PartnerController extends BaseController
{
    use PartnerTrait;

    /**
     * 获取合作者列表
     * @return string
     */
    public function getPartnerList()
    {
        $limit = $this->limit;
        $data = [
            'limit' => $limit
        ];
        $response = PartnerLogic::getPartnerList($data);
        if ($response->code){
            return self::response($response->code, $response->message);
        }
        return self::response($response->code, $response->message, $response->data);
    }

    /**
     * 获取合作者详情
     * @return string
     */
    public function getPartnerDetail()
    {
        $partner_id = $this->partner_id;
        $data = [
            'partner_id' => $partner_id
        ];
        $response = PartnerLogic::getPartnerDetailById($data);
        if ($response->code){
            return self::response($response->code, $response->message);
        }
        return self::response($response->code, $response->message, $response->data);
    }

    /**
     * 上传合作者LOGO
     * @return string
     */
    public function uploadLogo()
    {
        $logo_file = $this->logo_file;
        $data = [
            'logo_file' => $logo_file
        ];
        $response = PartnerLogic::uploadLogo($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 更新合作者信息
     * @return string
     */
    public function updatePartner()
    {
        $partner_id = $this->partner_id;
        $logo = $this->logo;
        $name = $this->name;
        $weixin_name = $this->weixin_name;
        $summary = $this->summary;
        $data = [
            'partner_id' => $partner_id,
            'logo' => $logo,
            'name' => $name,
            'weixin_name' => $weixin_name,
            'summary' => $summary
        ];
        $response = PartnerLogic::updatePartner($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 添加合作者
     * @return string
     */
    public function createPartner()
    {
        $name = $this->name;
        $weixin_name = $this->weixin_name;
        $logo = $this->logo;
        $summary = $this->summary;
        $data = [
            'name' => $name,
            'weixin_name' => $weixin_name,
            'logo' => $logo,
            'summary' => $summary
        ];
        $response = PartnerLogic::createPartner($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 删除合作者
     * @return string
     */
    public function deletePartner()
    {
        $partner_id = $this->partner_id;
        $data = [
            'partner_id' => $partner_id
        ];
        $response = PartnerLogic::deletePartner($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}